<template>
  <div id="referralInvitation">
    <h1 class="con-right-title">转介绍邀请记录</h1>
    <topSearch @toSearch="toSearch"></topSearch>
    <div class="table-conBtn">
      <el-button class="keepRight" type="success" @click="exportFile">
        导出Excel
      </el-button>
      <div class="statistics">
        <span>此活动参与人数：{{ statistics.joinCount || 0 }} 人 </span>
        <span>此活动入量人数：{{ statistics.flowCount || 0 }} 人 </span>
        <span>此活动开通试学课人数：{{ statistics.trialCount || 0 }} 人 </span>
        <span>此活动成单人数：{{ statistics.orderCount || 0 }} 人 </span>
        <span>此活动提现金额：{{ statistics.withdrawalAmount || 0 }} 元 </span>
      </div>
      <freshCom @searchList="searchList"></freshCom>
    </div>
    <!-- 表格 -->
    <el-table :data="tableData" max-height="550" v-loading="loading">
      <el-table-column type="index" label="序号" width="50" align="center">
      </el-table-column>
      <el-table-column
        label="邀请人"
        min-width="150"
        prop="adverUserName"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="邀请人大鹏号"
        min-width="100"
        prop="adverDpAccount"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="邀请人手机号"
        min-width="100"
        prop="adverPhone"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="被邀请人"
        min-width="100"
        prop="userName"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="被邀请人时间"
        min-width="150"
        prop="createTime"
        align="center"
      >
      </el-table-column>
      <el-table-column
        min-width="120"
        label="被邀请人大鹏号"
        prop="dpAccount"
        align="center"
      >
      </el-table-column>
      <el-table-column
        min-width="120"
        label="被邀请人手机号"
        prop="phone"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="试学课时间"
        min-width="150"
        prop="trialStatus"
        align="center"
      >
      </el-table-column>
      <el-table-column label="当前状态" min-width="100" align="center">
        <template v-slot="{ row }">
          <span v-if="row.trialType == '0'">注册未领课</span>
          <span v-if="row.trialType == '1'">已领课</span>
        </template>
      </el-table-column>
      <el-table-column
        label="活动名称"
        min-width="100"
        prop="activityName"
        align="center"
      >
      </el-table-column>
      <el-table-column label="活动状态" min-width="100" align="center">
        <template v-slot="{ row }">
          <span v-if="row.activityStatus == 'NOT_STARTED'">未开始</span>
          <span v-if="row.activityStatus == 'ONGOING'">进行中</span>
          <span v-if="row.activityStatus == 'OVER'">已结束</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="200" align="center">
        <template v-slot="{ row }">
          <el-button type="text" @click="toDetail(row)">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pageCom
      :searchParams="searchParams"
      @searchList="searchList"
      :total="total"
    ></pageCom>
    <!-- 查看详情dialog -->
    <chooseBounced
      v-if="chooseBounced.isShow"
      :dialog-data="chooseBounced"
    ></chooseBounced>
    <!-- 导出表单弹窗 -->
    <exportDialog :exportShow.sync="exportShow" />
  </div>
</template>

<script>
import topSearch from './topSearch'
import chooseBounced from './chooseBounced'
import exportDialog from './exportDialog'
import {
  getwithdrawList,
  getStatisticsList
} from '@/api/activityCenter/activityManage/inviteHaveGift'
export default {
  components: {
    topSearch,
    chooseBounced,
    exportDialog
  },
  data() {
    return {
      searchParams: {
        pageNum: 1, // 当前页数
        pageSize: 10, // 页面显示条数
        activityId: '634f89ea13922925dc8a3b17'
      },
      total: 0,
      loading: false,
      exportShow: false,
      tableData: [],
      statistics: {}, //统计
      chooseBounced: { isShow: false }
    }
  },
  watch: {
    'searchParams.activityId': {
      handler(val) {
        getStatisticsList(val, {}, (res) => {
          this.statistics = res
        })
      },
      immediate: true,
      deep: true
    }
  },
  mounted() {
    this.searchList()
  },
  methods: {
    /* 列表 */
    searchList() {
      this.loading = true
      getwithdrawList(
        this.searchParams,
        (res) => {
          this.loading = false
          this.tableData = res.rows
          this.total = res.total
        },
        () => {
          this.loading = false
        }
      )
    },
    // 查询按钮
    toSearch(val) {
      this.searchParams.pageNum = 1
      this.searchParams = { ...this.searchParams, ...val }
      this.searchList()
    },
    /* 导出 */
    exportFile() {
      this.exportShow = true
    },
    /* 查看详情 */
    toDetail(row) {
      const { activityId, adverDpAccount } = row
      this.chooseBounced = {
        isShow: true,
        obj: { activityId, dpAccount: adverDpAccount }
      }
    }
  }
}
</script>

<style lang="less" scoped>
.statistics {
  font-size: 16px;
  color: #0d1636;
  display: inline-block;
  span {
    margin-left: 35px;
  }
}
</style>
